package djl;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import djl.test.RobotTestBed;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;

/**
 * Illustrates JUnit testing of Robocode robots. This test simply verifies that DaBeast beats Crazy
 * half the time.
 * 
 * @author David Joel Lazaro Code borrowed from Philip Johnson.
 * 
 */
public class TestDaBeastVersusCrazy extends RobotTestBed {

  /**
   * Specifies that Crazy and DaBeast are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Crazy,djl.DaBeast";
  }

  /**
   * This test runs for 9 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 9;
  }

  /**
   * The actual test, which asserts that DaBeast has won half the time against Crazy.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] results = event.getIndexedResults();
    // Sanity check that results[1] is DaBeast (not strictly necessary, but illustrative).
    assertEquals("Check results[1]", results[1].getTeamLeaderName(), "djl.DaBeast");

    // Check to make sure DaBeast won half the time.
    assertTrue("Check DaBeast winner", results[1].getFirsts() >= getNumRounds() / 2);
  }
}
